package com.bang.study.day02.test;

import com.bang.study.day02.FileOperation;
import com.bang.study.day02.set.BSTSet;
import com.bang.study.day02.set.LinkedListSet;
import com.bang.study.day02.set.Set;

import java.util.ArrayList;

/**
 * @Auther: Bang
 * @Date: 2019/9/13 00:20
 * @Description:
 */
public class SetMain {

    private static double testSet(Set<String> set, String filename){
        System.out.println(filename);
        long startTime = System.nanoTime();
        ArrayList<String> words = new ArrayList<>();
        if(FileOperation.readFile(filename, words)) {
            System.out.println("Total words: " + words.size());

            startTime= System.nanoTime();
            for (String word : words) {
                set.add(word);
            }
            System.out.println("Total different words: " + set.getSize());
        }
        long endTime = System.nanoTime();
        return (endTime-startTime)/1000000000.0;
    }

    public static void main(String[] args) {
        String filename = "pride-and-prejudice.txt";

        BSTSet<String> bstSet = new BSTSet<>();
        double time1 = testSet(bstSet, filename);
        System.out.println("BST Set: " + time1 + " s");

        System.out.println();

        LinkedListSet<String> linkedListSet = new LinkedListSet<>();
        double time2 = testSet(linkedListSet, filename);
        System.out.println("Linked List Set: " + time2 + " s");
    }
}
